var gCtx = null;
var gCanvas = null;

var imageData = null;
var ii=0;
var jj=0;
var c=0;

function pageLoad() { 
  initCanvas(320,240);
} 


function initCanvas(ww,hh)
{
  gCanvas = document.getElementById("canvas");
  var w = ww;
  var h = hh;
  gCanvas.style.width = w + "px";
  gCanvas.style.height = h + "px";
  gCanvas.width = w;
  gCanvas.height = h;
  gCtx = gCanvas.getContext("2d");
  gCtx.clearRect(0, 0, w, h);
  imageData = gCtx.getImageData( 0,0,320,240);
}

function passLine(stringPixels) { 
  //a = (intVal >> 24) & 0xff;

  var coll = stringPixels.split("-");
  
  for(var i=0;i<320;i++) { 
    var intVal = parseInt(coll[i]);
    r = (intVal >> 16) & 0xff;
    g = (intVal >> 8) & 0xff;
    b = (intVal ) & 0xff;
    var media = parseInt( (r+g+b) /3 );
    imageData.data[c+0]=media;
    imageData.data[c+1]=media;
    imageData.data[c+2]=media;
    imageData.data[c+3]=255;
    c+=4;
  } 
  
  if(c>=320*240*4) { 
    c=0;
    gCtx.putImageData(imageData, 0,0);
  } 
}

function captureToCanvas() {
  console.log("take");
  flash = document.getElementById("embedflash");
  flash.ccCapture();
}
//pageLoad();